﻿@model DataBaseInfoModel
<script src="@Url.Content("~/Scripts/jquery/ZeroClipboard/jquery.zclip.js")" type="text/javascript"></script>
@{
    Layout = "Common";

    System.Collections.Concurrent.ConcurrentDictionary<string, string> errors = TempData["Error"] as System.Collections.Concurrent.ConcurrentDictionary<string, string>;
}
<div class="spb-step-2">
    <div class="spb-step-slide spb-bg">
        <ul>
            <li class="spb-step-slide-1">环境检测</li>
            <li class="spb-step-slide-2 spb-selected">数据安装</li>
            <li class="spb-step-slide-3">完成安装</li>
        </ul>
    </div>
    @using (Html.BeginForm("Step2_Wait", "Install", FormMethod.Post, new { name = "dbform" }))
    {
        <div class="spb-data-wrap">
            <div class="spb-data-inst">
                @if (errors != null && errors.Keys.Count > 0)
                {
                    <div class="spb-tip-box">
                        <p>
                            <span class="spb-bg spb-icon spb-icon-exclamation"></span><strong>@errors.Keys.FirstOrDefault()</strong>
                        </p>
                    </div>
                }
                <div class="spb-form">
                    <div class="spb-title">
                        <strong>数据库信息</strong>
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            数据库服务器类型：
                        </div>
                        <div class="spb-form-item">
                            @Html.EnumDropDownListFor(n => n.DBType)
                        </div>
                        @Html.ValidationMessageFor(n => n.DBType)
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            数据库服务器：
                        </div>
                        <div class="spb-form-item">
                            @Html.TextBoxFor(n => n.Server, new { @class = "spb-textbox" })
                        </div>
                        @Html.ValidationMessageFor(n => n.Server)
                    </div>
                    <div class="spb-switch">
                        <a href="javascript:;" id="more"><em>更多设置</em><span class="spb-bg spb-icon spb-icon-collapse-open"></span></a>
                    </div>
                    <div style="display: none;" class="spb-more-set" id="moreOption">
                        <div class="spb-form-row">
                            <div class="spb-label">
                                实例名：
                            </div>
                            <div class="spb-form-item">
                                @Html.TextBoxFor(n => n.Instance, new { @class = "spb-textbox" })
                            </div>
                            @Html.ValidationMessageFor(n => n.Instance)
                        </div>
                        <div class="spb-form-row">
                            <div class="spb-label">
                                端口号：
                            </div>
                            <div class="spb-form-item">
                                @Html.TextBoxFor(n => n.Port, new { @class = "spb-textbox" })
                            </div>
                            @Html.ValidationMessageFor(n => n.Port)
                        </div>
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            数据库名称：
                        </div>
                        <div class="spb-form-item">
                            @Html.TextBoxFor(n => n.DataBase, new { @class = "spb-textbox" })
                        </div>
                        @Html.ValidationMessageFor(n => n.DataBase)
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            数据库用户帐号：
                        </div>
                        <div class="spb-form-item">
                            @Html.TextBoxFor(n => n.DataBaseUserName, new { @class = "spb-textbox" })
                        </div>
                        @Html.ValidationMessageFor(n => n.DataBaseUserName)
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            数据库用户密码：
                        </div>
                        <div class="spb-form-item">
                            @Html.TextBoxFor(n => n.DataBasePassword, new { @class = "spb-textbox", type = "password" })
                        </div>
                        <div class="spb-show-password">
                            <label>
                                <input type="checkbox" id="showdbpassword" />
                                显示密码</label>
                        </div>
                    </div>
                    <div class="spb-title">
                        <strong>创始人信息</strong>
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            管理员帐号：
                        </div>
                        <div class="spb-form-item">
                            @Html.TextBoxFor(n => n.Administrator, new { @class = "spb-textbox" })
                        </div>
                        @Html.ValidationMessageFor(n => n.Administrator)
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            密码：
                        </div>
                        <div class="spb-form-item">
                            @Html.TextBoxFor(n => n.UserPassword, new { @class = "spb-textbox", type = "password" })
                        </div>
                        <div class="spb-show-password">
                            <label>
                                <input type="checkbox" id="showuserpassword" />
                                显示密码</label>
                        </div>
                    </div>
                    <div class="spb-title">
                        <strong>站点信息</strong>
                    </div>
                    <div class="spb-form-row">
                        <div class="spb-label">
                            主站域名：
                        </div>
                        <div class="spb-form-item">
                            @Html.TextBoxFor(n => n.MainRootSiteUrl, new { @class = "spb-textbox" })
                        </div>
                    </div>
                </div>
            </div>
        </div>
    }
</div>
@section Footer{
    <div class="spb-ft">
        <a href="@Url.Action("Step1_EnvironmentCheck", "Install")" class="spb-btn">上一步</a><a
            href="javascript:;" class="spb-btn" id="start">开始安装</a>
    </div>
}
<script type="text/javascript">
    $(document).ready(function () {

        if (!$.browser.msie && i_flash) {
            $("#copy").zclip({
                path: '@Tunynet.Utilities.WebUtility.ResolveUrl(@"~/Scripts/jquery/ZeroClipboard/ZeroClipboard.swf")',
                copy: function () {
                    return $('#stackTrace').val();
                },
                afterCopy: function () {
                    alert("复制完成");
                }
            });
        } else {
            $("#stackTrace").click(function () {
                copyToClipboard($('#stackTrace').val());
            });
        }

        $('#more').click(function () {
            if ($(this).find('span').hasClass("spb-icon-collapse-open")) {
                $(this).find('span').removeClass("spb-icon-collapse-open")
                       .addClass("spb-icon-collapse-close");
                $('#moreOption').show();
            }
            else {
                $(this).find('span').removeClass("spb-icon-collapse-close")
                       .addClass("spb-icon-collapse-open");
                $('#moreOption').hide();
            }
        });

        $('#showdbpassword').click(function () {
            var obj = $('#DataBasePassword');
            var password = obj.val();

            if ($(this).is(':checked')) {
                obj.after('<input id="' + obj.attr('id') + '" name="' + obj.attr('name') + '" type="text" class="spb-textbox"/>');
                obj.remove();
                $('#DataBasePassword').val(password);
            }
            else {
                obj.after('<input id="' + obj.attr('id') + '" name="' + obj.attr('name') + '" type="password" class="spb-textbox"/>');
                obj.remove();
                $('#DataBasePassword').val(password);
            }
        });

        $('#showuserpassword').click(function () {
            var obj = $('#UserPassword');
            var password = obj.val();

            if ($(this).is(':checked')) {
                obj.after('<input id="' + obj.attr('id') + '" name="' + obj.attr('name') + '" type="text" class="spb-textbox"/>');
                obj.remove();
                $('#UserPassword').val(password);
            }
            else {
                obj.after('<input id="' + obj.attr('id') + '" name="' + obj.attr('name') + '" type="password" class="spb-textbox"/>');
                obj.remove();
                $('#UserPassword').val(password);
            }
        });

        $('#start').click(function () {
            $('form[name="dbform"]').submit();
            return false;
        });

        $('#MainRootSiteUrl').val('http://' + document.location.host);
        $("#DBType").change(function () {
            if ($(this).val() == "MySql")
            {
                $("#DataBaseUserName").val("root");
            }
            if ($(this).val() == "SqlServer") {
                $("#DataBaseUserName").val("sa");
            }
        });
    });

    function copyToClipboard(txt) {
        if (window.clipboardData) {

            window.clipboardData.clearData();
            window.clipboardData.setData("Text", txt);
            alert("复制完成，现在将邀请链接黏贴给您的好友吧");
        } else if (navigator.userAgent.indexOf("Opera") != -1) {
            window.location = txt;
        } else if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
            }
            var clip = Components.classes['@@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip)
                return;
            var trans = Components.classes['@@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans)
                return;
            trans.addDataFlavor('text/unicode');
            var str = new Object();
            var len = new Object();
            var str = Components.classes["@@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            var copytext = txt;
            str.data = copytext;
            trans.setTransferData("text/unicode", str, copytext.length * 2);
            var clipid = Components.interfaces.nsIClipboard;
            if (!clip)
                return false;
            clip.setData(trans, null, clipid.kGlobalClipboard);
            alert("复制完成")
        }
    }
</script>
<script type="text/javascript"><!--
    var i_flash;
    // Netscape  
    if (navigator.plugins) {
        for (var i = 0; i < navigator.plugins.length; i++) {
            if (navigator.plugins[i].name.toLowerCase().indexOf("shockwave flash") >= 0) {
                i_flash = true;
            }
        }
    }
    // -->
</script>
<script type="text/vbscript">
<!-- 
//IE 
on error resume next 
set f = CreateObject("ShockwaveFlash.ShockwaveFlash") 
if IsObject(f) then 
i_flash = true 
end if 
// -->
</script>
